package com.rayo.accesscontrollercopy.module.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rayo.accesscontrollercopy.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yanghaojie on 16/7/27.
 */
public class InfoAdapter extends RecyclerView.Adapter<InfoAdapter.InfoViewHolder> {
    List<String> mDatas;

    public InfoAdapter() {
        this.mDatas = new ArrayList<>();
    }

    @Override
    public InfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        InfoViewHolder holder = new InfoViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.adapter_info, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(InfoViewHolder holder, int position) {
        holder.mTxtInfoe.setText(mDatas.get(position));
    }

    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    public void addItems(String list) {
        if (list == null)
            return;
        this.mDatas.add(list);
        this.notifyItemRangeInserted(mDatas.size(), 1);
    }

    public void clean() {
        this.mDatas.clear();
        this.notifyDataSetChanged();
    }

    class InfoViewHolder extends RecyclerView.ViewHolder {
        TextView mTxtInfoe;

        public InfoViewHolder(View view) {
            super(view);
            mTxtInfoe = (TextView) view.findViewById(R.id.tv_adapter_info);
        }
    }
}
